package com.hwua.view;

import com.hwua.dao.UserDao;
import com.hwua.daoimpl.UserDaoImpl;
import com.hwua.service.UserService;
import com.hwua.serviceimpl.UserServiceImpl;
import com.hwua.util.IdentifyingCodeTools;
import com.hwua.util.InputTools;

/**
 * 注册界面
 * @author admin
 */
public class RegisterView extends AbstractView{
    @Override
    public AbstractView showView() {
        UserService us = new UserServiceImpl();
        System.out.println("=========注册========>>>>>");
        System.out.println("请输入用户名：");
        String name = InputTools.nextString();
        System.out.println("请输入密  码：");
        String pwd = InputTools.nextString();
        while(true){
            //获取随机四位验证码
            int identifyingCode = IdentifyingCodeTools.createIdentifyingCode();
            System.out.println("验证码："+identifyingCode);
            System.out.println("请输入验证码：☟☟☟☟☟☟☟☟");
            int num = InputTools.checkIntInput(0, 9999);
            if(num==identifyingCode){
                break;
            }
            System.out.println("验证码错误，请重新输入：");
        }
        boolean result = us.register(name, pwd);
        if(result){
            System.out.println("注册成功！");
            nextView = new LoginView();
        }else{
            System.out.println("用户名已存在，请重新注册！");
            nextView = new RegisterView();
        }
        return nextView;
    }
}
